"use strict";
//define namespaces
var FIUMAPS = {}; 
//FIUMAPS.URLParameters = {}; 
var gmap = null;
var mapExtension = null;
FIUMAPS.Directories = {"Images":"","Root":""};
FIUMAPS.Directories.Root = getRootWebDirectory();
FIUMAPS.Directories.Images = FIUMAPS.Directories.Root + "css/images/";
var IE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1)
&& (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1);
//var current_campus_id = null;
var current_category_id = null;
var printmode = false;
var mymapLayers,myLocationsbyName,identifyTask;
var current_tab = "";
//Define Constants for types of locations.
FIUMAPS.LocationTypes = {"SERVICE":0,"BUILDING":1};
FIUMAPS.GMarkers = { Marker: { "DEFAULT": FIUMAPS.Directories.Images + "marker_fiu.png", "HOVER": FIUMAPS.Directories.Images + "marker_yellow.png"} };

if (IE6) {
    window.location = "ie6.html"
}
//function test() {

//    
//    
//}
function getRootWebDirectory(){
    var URLPath = window.location.protocol + "//" + window.location.host + window.location.pathname;
    if (URLPath.indexOf("index") > -1) URLPath = URLPath.substring(URLPath.indexOf("index"),0);       
    return URLPath;
}

function initialize() {


    if (GBrowserIsCompatible()) {

        // GMap construction
        gmap = new GMap2($('mapid'));


        //Create MapExtension utility class
        mapExtension = new esri.arcgis.gmaps.MapExtension(gmap);


        // Add ExtMapTypeControl with posRight option
        gmap.addControl(new ExtMapTypeControl({ posRight: 220, showTraffic: true, showTrafficKey: true, showMore: true }));

        // Add GHierarchicalMapTypeControl
        var hControl = new GHierarchicalMapTypeControl();
        hControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", true);
        //add maptypes
        gmap.addControl(hControl);
        //add navigation control
        //gmap.addControl(new GSmallZoomControl());

        gmap.addControl(new GOverviewMapControl());
        gmap.addControl(new GScaleControl());

        // create an identify task
        identifyTask = new esri.arcgis.gmaps.IdentifyTask("http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/ServicesNBuildings/MapServer/");
        // register click event listener for the map
        GEvent.addListener(gmap, "click", FIUMAPS.Identify.IdentifyPoint);

        //gmap.enableScrollWheelZoom();
        //gmap.enableGoogleBar();
        //gmap.disableDoubleClickZoom();

        //google's 3d earth plugin.
        //gmap.addMapType(G_SATELLITE_3D_MAP);

        mymapLayers = new FIUMAPS.mapLayers();

        mymapLocations = new FIUMAPS.myLocations();
        // Load global variables from URL:
        getQueryParameters();

        FIUMAPS.LocationsByName.LoadAlphabet();

        //FIUMAPS.HTMLPopUp.getServicesByBuildingID(1);

        
    }

}
//make any div modal.
FIUMAPS.ModalWindow = {
    isVisible: false,
    reloadOptionTimer: null,
    showReloadOption: function() {
        //only show reload option if modal screen is visible.
        if (!this.isVisible) {
            $('ReloadOption').removeClass('hidden');
        }
    },
    show: function(div) {
        this.isVisible = true;
        $('ModalContent').innerHTML = div.innerHTML;
        $('MapModal').removeClass('hidden');
        $('MapModal').fade('toggle');
        this.reloadOptionTimer = this.showReloadOption.delay(8000); //wait 8 seconds to show reload option.

    },
    hide: function() {
        this.isVisible = false;
        
        this.reloadOptionTimer = $clear(this.reloadOptionTimer); //clear timer.
        $('MapModal').addClass('hidden');
        $('MapModal').fade('toggle');
        $('ModalContent').innerHTML = "";
    }
}
function searchBottonKeyDown(event){
  if (event.keyCode == 13) {$('searchbutton').fireEvent('click');}       
}
function setMailToURL(){
    var urlParamItem = new FIUMAPS.URLParameters();
    var mailtoString = "mailto:?subject=FIU Campus Maps&body=" + urlParamItem.GenerateURL(false).replace(/&/gi, "%26");
    $('EmailLink').set('href',mailtoString);
}
function setPrintToURL(){
    var urlParamItem = new FIUMAPS.URLParameters();
    var printString = "print.html" + urlParamItem.GenerateURL(true);
    $('PrintLink').set('href',printString);
}
function getQueryParameters(){

    //if cid parameter is present load map from querystring..
    if(URLDecode(getQuerystring('cid'))){
        var urlParamItem = new FIUMAPS.URLParameters();
        urlParamItem.LoadURL();
    }else{
        FIUMAPS.CampusInfo.goToCampusByID(FIUMAPS.CampusInfo.getCurrentCampusID());
    }
}  

function URLDecode(psEncodeString)
{
    // Create a regular expression to search all +s in the string
    var lsRegExp = /\+/g;
    // Return the decoded string
    return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

function getQuerystring(key, default_)
{
    if (default_==null) default_="";
    key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if(qs == null)
        return default_;
    else
        return qs[1];
}  
function LoadLetter(letter){
    FIUMAPS.LocationsByName.LoadLetter(letter);
}

FIUMAPS.mapLayers = function() {
    
    var arrTileLayers = [{"Name":"Background",
                        "URLs":["http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/UP_Background/MapServer",
                                "http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/BBC_Background/MapServer"],
                        "Priority":1,
                        "IsVisibleByDefault":false,
                        "chkBoxElement":null,
                        "Opacity":1,
                        "gOverlay":[]},// array of gOverlay[][]
                        {"Name":"Buildings",
                        "URLs":["http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/UP_Buildings_Mercator/MapServer",
                                "http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/BBC_Buildings_Mercator/MapServer",
                                "http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/ENG_Buildings_Mercator/MapServer",
                                "http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/TPC_Buildings/MapServer",
                                "http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/WLF_Buildings_Mercator/MapServer",
                                "http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/MET_Buildings_Mercator/MapServer"],
                        "Priority":6,
                        "IsVisibleByDefault":true,
                        "chkBoxElement":null,
                        "Opacity":0.65,
                        "gOverlay":[]},
                        {"Name":"Bike Racks",
                        "URLs":["http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/UP_BikeRacks/MapServer"],
                        "Priority":7,
                        "IsVisibleByDefault":true,
                        "chkBoxElement":null,
                        "Opacity":1,
                        "gOverlay":[]}];   

    //mmc
    var mmcBackground = new esri.arcgis.gmaps.TiledMapServiceLayer(arrTileLayers[0].URLs[0], {opacity: arrTileLayers[0].Opacity, minResolution:0, maxResolution: 19}, addLayer_CallBack);
    GEvent.addListener(mmcBackground, "load", function() {
        var mmcBuildings = new esri.arcgis.gmaps.TiledMapServiceLayer(arrTileLayers[1].URLs[0], {opacity: arrTileLayers[1].Opacity, minResolution:0, maxResolution: 19}, addLayer_CallBack);
        GEvent.addListener(mmcBuildings, "load", function() {
            var mmcBikeRacks = new esri.arcgis.gmaps.TiledMapServiceLayer(arrTileLayers[2].URLs[0], {opacity: arrTileLayers[2].Opacity, minResolution:0, maxResolution: 19}, addLayer_CallBack);
        });
    });       
    //bbc
    var bbcBackground = new esri.arcgis.gmaps.TiledMapServiceLayer(arrTileLayers[0].URLs[1], {opacity: arrTileLayers[0].Opacity, minResolution:0, maxResolution: 19}, addLayer_CallBack);
    GEvent.addListener(bbcBackground, "load", function() {
        var bbcBuildings = new esri.arcgis.gmaps.TiledMapServiceLayer(arrTileLayers[1].URLs[1], {opacity: arrTileLayers[1].Opacity, minResolution:0, maxResolution: 19}, addLayer_CallBack);
        GEvent.addListener(bbcBuildings, "load", function() {
            //var bbcBikeRacks = new esri.arcgis.gmaps.TiledMapServiceLayer(arrTileLayers[2].URLs[1], {opacity: arrTileLayers[2].Opacity, minResolution:0, maxResolution: 19}, addLayer_CallBack);
        });
    }); 
    //ENG
    var encBuildings = new esri.arcgis.gmaps.TiledMapServiceLayer(arrTileLayers[1].URLs[2], {opacity: arrTileLayers[1].Opacity, minResolution:0, maxResolution: 19}, addLayer_CallBack);
    //TPC
    var tpcBuildings = new esri.arcgis.gmaps.TiledMapServiceLayer(arrTileLayers[1].URLs[3], {opacity: arrTileLayers[1].Opacity, minResolution:0, maxResolution: 19}, addLayer_CallBack);      
    //WLF
    var wlfBuildings = new esri.arcgis.gmaps.TiledMapServiceLayer(arrTileLayers[1].URLs[4], {opacity: arrTileLayers[1].Opacity, minResolution:0, maxResolution: 19}, addLayer_CallBack);    
    //MET
    var metBuildings = new esri.arcgis.gmaps.TiledMapServiceLayer(arrTileLayers[1].URLs[5], {opacity: arrTileLayers[1].Opacity, minResolution:0, maxResolution: 19}, addLayer_CallBack);    
               
    CreateHTMLNavigation("ulMapLayers");
    
    
    
    function CreateHTMLNavigation(ulID){ 
    
        //loop through arrTileLayers array
        for (var i = 0; i < arrTileLayers.length; i++) { 
        
            var listItem = document.createElement('li');
            var label = document.createElement('label');
            

            var chkBox = document.createElement('input');
            chkBox.type = "checkbox";
            
            chkBox.onclick=Function("toggleLayerVisibility('" + arrTileLayers[i].Name + "')");
            
            label.appendChild(chkBox);
            chkBox.checked = arrTileLayers[i].IsVisibleByDefault;
            
            label.appendChild(document.createTextNode(" " + arrTileLayers[i].Name));
            listItem.appendChild(label);
            $(ulID).appendChild(listItem); 
            
            //store checkbox element for later manipulation.
            arrTileLayers[i].chkBoxElement = $(chkBox);
        }
    }      
    function addLayer_CallBack (gTileLayer){

        //Add tile layer as a GTileLayerOverlay using mapExtension
        var gOverlay = mapExtension.addToMap(gTileLayer); // gOverlay[][]
        // store gOverlay[][] in it's appropriate spot in arrTileLayers
        for (var j = 0; j < gOverlay.length; j++) { 
            for (var x = 0; x < gOverlay[j].length; x++) {                     
                //loop through arrTileLayers array
                for (var i = 0; i < arrTileLayers.length; i++) { 
                    for (var z = 0; z < arrTileLayers[i].URLs.length; z++) { 
                        if(gTileLayer.url == arrTileLayers[i].URLs[z]){
                            //store gOverlay[][] in it's appropriate spot in arrTileLayers
                            arrTileLayers[i].gOverlay.push(gOverlay);
                            // hide layer if it is set to not show by default.
                            if(!arrTileLayers[i].IsVisibleByDefault){
                                gOverlay[j][x].hide();
                            }
                        }
                    }
                }
            } 
        }
    }         
    this.getVisibleLayerIDs = function (){
        //loop through arrTileLayers array to check if layers are visible.
        var arrLayerIds = new Array();
        for (var i = 0; i < arrTileLayers.length; i++) { 
            for (var z = 0; z < arrTileLayers[i].gOverlay.length; z++) { 
                for (var j = 0; j < arrTileLayers[i].gOverlay[z].length; j++) { 
                    for (var x = 0; x < arrTileLayers[i].gOverlay[z][j].length; x++) {
                        if(arrTileLayers[i].gOverlay[z][j][x].isHidden() == false){
                            if(arrLayerIds.indexOf(i) == -1){
                                arrLayerIds.push(i);
                            }
                        }
                    }
                }
            }           
        }   
        
        return arrLayerIds.toString();   
    };
    // sets the default visibility for layers by comma delimited IDs.
    this.setDefaultVisibilityIDs = function (layerIds){
        
        var arrLayerIds = layerIds.split(',');
        for (var i = 0; i < arrTileLayers.length; i++) { 
            //if ID is found then show change the "IsVisibleByDefault" property.
            if(arrLayerIds.indexOf(i.toString()) > -1){
                arrTileLayers[i].IsVisibleByDefault = true;
                $(arrTileLayers[i].chkBoxElement).checked = true;
            }else{
                arrTileLayers[i].IsVisibleByDefault = false;
                $(arrTileLayers[i].chkBoxElement).checked = false;
            }
        }        
    };     
    this.toggleLayerVisibility = function (name){ 
        //loop through arrTileLayers array to find name and display or hide it's gOverlays
        for (var i = 0; i < arrTileLayers.length; i++) { 
            if(arrTileLayers[i].Name == name){
                for (var z = 0; z < arrTileLayers[i].gOverlay.length; z++) { 
                    for (var j = 0; j < arrTileLayers[i].gOverlay[z].length; j++) { 
                        for (var x = 0; x < arrTileLayers[i].gOverlay[z][j].length; x++) {
                            if(arrTileLayers[i].gOverlay[z][j][x].isHidden() == true){
                                arrTileLayers[i].gOverlay[z][j][x].show();
                            }else{
                                arrTileLayers[i].gOverlay[z][j][x].hide();
                            }
                        }
                    }
                } 
                return;           
            }
        }        
    };            
}

FIUMAPS.myLocations = function() {
    var myLocations = new Array();

    var hasServicesHeader = false;
    var hasBuildingsHeader = false;
    var buildings_ul,services_ul;
    var isTabActive = false;
    
    this.getMyLocations = function () {
        return myLocations;
    }; 
       
    this.IsActive = function (){
        return isTabActive;
    };
    this.addtoMyLocations = function (geom,attributes) {
        //Only add it if item does not exist.          
        if(!alreadyExists(attributes)){      
            // add geometry and attributes to mylocations array.
            myLocations.push({ "geometries" : [geom], "attributes"  : attributes });
            // increment My Locations Header Count
            $('myLocationsHeader').innerHTML = "<strong>My Locations (" + myLocations.length + ")</strong>"; 
        }
    };   
    this.hideGeometries = function(){
        ClearOverlays();   
        $('myLocations').innerHTML = "";     
        hasServicesHeader = false;
        hasBuildingsHeader = false;
        isTabActive = false;
    }; 
    this.showGeometries = function(){
        //only reload if user is not currently on the tab already. 
        if(!isTabActive){
            // clear map overlays
            ClearOverlays();
            for (var x = 0; x < myLocations.length; x++){
                generateHTMLAndMap(myLocations[x].geometries,myLocations[x].attributes);                                                            
            } 
            isTabActive = true;
        }
    };      
    this.getCount = function(){   
        return myLocations.length;
    }; 
    function alreadyExists (attributes){
        var att;
        if(myLocations){
            if(!attributes.SERVICE_ID){//item is a building
                for (var x = 0; x < myLocations.length; x++){
                    att = myLocations[x].attributes;
                    if(att.BUILDING_ID == attributes.BUILDING_ID){
                        return true;
                    }
                }
            }else{//item is a service
                for (var x = 0; x < myLocations.length; x++){
                    att = myLocations[x].attributes;
                    if(att.SERVICE_ID == attributes.SERVICE_ID){
                        return true;
                    }
                }     
            }        
        } 
        return false;
    }                   
    function generateHTMLAndMap (geometry,attributes){ 
    
        // create html list item element
        var li = document.createElement('li');
        // create html link item element
        var link = CreateLinkElement(attributes.NAME);
        
        if(!attributes.SERVICE_ID){
            //Buildings/ GPolygon
            //add hover rules to all geometries associated to this feature.         
            addPolygonListeners(geometry,attributes,link);
        }else{
            // Services/GMarker
            //add hover rules to all geometries associated to this feature.
            addPointListeners(geometry,attributes,link);
        }                           
        // add link to list item container
        li.appendChild(link);
        
        addToList(attributes,li);

    }  
    function addToList(attributes,li){ 
        // add this item to HTML list.
        if(!attributes.SERVICE_ID){//item is a building
            if(!hasBuildingsHeader){
                //Services header does not exist in list, create it.
                buildings_ul = document.createElement('ul');
                CreateHeader("Buildings",buildings_ul);
                hasBuildingsHeader = true;         
            }          
            buildings_ul.appendChild(li);
        }else{//item is a service
            if(!hasServicesHeader){
                //Services header does not exist in list, create it.
                services_ul = document.createElement('ul');
                CreateHeader("Services",services_ul);
                hasServicesHeader = true;         
            }        
            services_ul.appendChild(li); 
        }
    }                   
    function CreateHeader(label,htmlElement){   
        var h5 = document.createElement('h5');
        h5.appendChild(document.createTextNode(label));
        $('myLocations').appendChild(h5);
        $('myLocations').appendChild(htmlElement); 
    }  
    function CreateLinkElement(label){   
        // create html link element 
        var link = document.createElement('a');
        link.style.cursor = 'pointer';
        link.style.marginBottom = '5px';
        link.title = label;
        link.appendChild(document.createTextNode(label));
        return link;    
    }
                  
}
function toggleLayerVisibility(layerIDs){
    mymapLayers.toggleLayerVisibility(layerIDs);
}

var showSearchInstructions = function(){
    var div = $('searchinstructions').setStyles({display:'block'});
    var div = $('searchresults').setStyles({display:'none'});
    var div = $('searchprogress').setStyles({display:'none'});    
   // new Fx.Style(div, 'opacity', {duration: 1000} ).start(1);
   accordionResize('searchinstructions');
}
var showSearchProgress = function(){
    var div = $('searchresults').setStyles({display:'none'});
    var div = $('searchinstructions').setStyles({display:'none'});
    var div = $('searchprogress').setStyles({display:'block'});
   // new Fx.Style(div, 'opacity', {duration: 1000} ).start(1);
   accordionResize('searchprogress');
}
var showSearchResultsDiv = function(){
    var div = $('searchresults').setStyles({display:'block'});
    var div = $('searchprogress').setStyles({display:'none'});
    
   // new Fx.Style(div, 'opacity', {duration: 1000} ).start(1);
   accordionResize('searchresults');
}


// show info window for the polygon when the user clicks on it
function PolyonClickFunc(attributes,isOnMap) {
    var polygon = this;
    
    // if clicking on map, show pop-up. else if clicking on html list results add to "myLocations".
    if(isOnMap){
        FIUMAPS.HTMLPopUp.Center = polygon.getBounds().getCenter();
        //open info window
        FIUMAPS.HTMLPopUp.openPolygonPopup(attributes);
        
    }else{//add to "myLocations"
        mymapLocations.addtoMyLocations(polygon,attributes);
    }

}
// show info window for the polygon when the user moves the mouse over it
function PolyonMouseOverFunc(attributes,isOnMap) {
//    // highlight the building
    var polygon = this;
    polygon.setFillStyle({ color: "#E9BD39" });
    polygon.setStrokeStyle({ color: "#E9BD39" });
//    // only if hovering over the results html and not the map
    if(!isOnMap){
        if(attributes.CAMPUS_ID != FIUMAPS.CampusInfo.getCurrentCampusID()){
            FIUMAPS.CampusInfo.goToCampusByID(attributes.CAMPUS_ID);
        }
        // show the infowindow
                
//        var html = FIUMAPS.HTMLPopUp.getPolygonHTMLWindows(attributes);
//        
//        gmap.openInfoWindowHtml(polygon.getBounds().getCenter(), html);
//        //gmap.panTo(polygon.getBounds().getCenter());
//        gmap.updateCurrentTab(mod);
        FIUMAPS.HTMLPopUp.Center = polygon.getBounds().getCenter();
//        
        FIUMAPS.HTMLPopUp.openPolygonPopup(attributes);
    }

}
function mod(res){
    // do nothing.
}
// close info window when the user moves the mouse out
function PolyonMouseOutFunc(isOnMap) {
    // unhighlight the county
    var polygon = this;
    polygon.setFillStyle({ color: "#0000FF" });
    polygon.setStrokeStyle({ color: "#0000FF" });
    
    // hide the infowindow
    if(!isOnMap){gmap.closeInfoWindow();}
    
}

// show info window for the county when the user moves the mouse over it
function MarkeronMouseClickFunc(marker,attributes,isOnMap) {

    mymapLocations.addtoMyLocations(marker,attributes);

}
// show info window for the county when the user moves the mouse over it
function MarkeronMouseOverFunc(attributes,isOnMap) {

    var myGMarker = this;
    // show the infowindow
    var html = FIUMAPS.HTMLPopUp.getMarkerHTMLWindows(attributes);
    // center map on campus if mouse is not on the map but on results, 
    // and map is currently not on the correct campus.
    if(!isOnMap){
        if(attributes.CAMPUS_ID != FIUMAPS.CampusInfo.getCurrentCampusID()){
            FIUMAPS.CampusInfo.goToCampusByID(attributes.CAMPUS_ID);
        }    
    }
        
    gmap.openInfoWindowHtml(myGMarker.getLatLng(), html);

}

// close info window when the user moves the mouse out of a county
function MarkeronMouseOutFunc() {

    //console.debug("polygon.geometryType:" + polygon.geometryType);
    // hide the infowindow
    gmap.closeInfoWindow();
}

function getFloorLabel(strFloor){
    var strFloorLabel;
    switch (strFloor) {
        case 1:
            strFloorLabel = "1st"
            break        
        case 2:
            strFloorLabel = "2nd"
            break
        case 3:
            strFloorLabel = "3rd"
            break
        case 4:
            strFloorLabel = "4th"
            break
        case 5:
            strFloorLabel = "5th"
            break
        case 6:
            strFloorLabel = "6th"
            break
        case 7:
            strFloorLabel = "7th"
            break
        case 8:
            strFloorLabel = "8th"
            break     
        case 9:
            strFloorLabel = "9th"
            break   
        case 10:
            strFloorLabel = "10th"
            break   
        case 11:
            strFloorLabel = "11th"
            break                                                                              
    }      

    return strFloorLabel;
}  
// Add Overlay to map.
FIUMAPS.Overlays = {Data:null};
function AddOverlay(geom, attributes){

    if (!FIUMAPS.Overlays.Data){
        FIUMAPS.Overlays.Data = [];
    }   
    // keep track of overlays so they can be cleared later.
    //mapOverlays.push([geom,attributes]);
    FIUMAPS.Overlays.Data.push([geom,attributes]);
    
    // Add geometry to map.
    gmap.addOverlay(geom);
    
}
// Remove Overlays from map
function ClearOverlays(){
    
    if (FIUMAPS.Overlays.Data){
    
        for (var z = 0; z < FIUMAPS.Overlays.Data.length; z++){
            gmap.removeOverlay(FIUMAPS.Overlays.Data[z][0]);
        }
        FIUMAPS.Overlays.Data = null;    
    }

}

function addPolygonListeners(geometry,attributes,link){
    for (var z = 0; z < geometry.length; z++) { // Feature.geometry is an array of GPolygon/GPolyline/GMarker
        var geom = geometry[z];
        // add event listener to geometries
        GEvent.addListener(geom, "click", GEvent.callbackArgs(geom, PolyonClickFunc, attributes, true));
        GEvent.addListener(geom, "mouseover", GEvent.callbackArgs(geom, PolyonMouseOverFunc, attributes, true));
        GEvent.addListener(geom, "mouseout", GEvent.callbackArgs(geom, PolyonMouseOutFunc, true));
        // add geometry overlay to map.
        AddOverlay(geom,attributes);
        if(link){
            // add event listener to result links
            GEvent.addDomListener(link, 'mouseover', GEvent.callbackArgs(geom, PolyonMouseOverFunc, attributes, false));                
            GEvent.addDomListener(link, 'mouseout', GEvent.callbackArgs(geom, PolyonMouseOutFunc, false));                 
            GEvent.addDomListener(link, 'click', GEvent.callbackArgs(geom, PolyonClickFunc, attributes, false));            	                               
        }
    }  
}

FIUMAPS.Points = {Tracker:[],GMarkers:{'main':[],'hover':[]}};

function addPointListeners(geometry,attributes,link){

    for (var z = 0; z < geometry.length; z++) { // Feature.geometry is an array of GPolygon/GPolyline/GMarker
        var geom = geometry[z];
       
        var hoverMarker,defaultMarker;
        

        var indexofPoint = FIUMAPS.Points.Tracker.indexOf(attributes.SERVICE_ID);             
        if(indexofPoint > -1){

            hoverMarker = FIUMAPS.Points.GMarkers.hover[indexofPoint];
            defaultMarker = FIUMAPS.Points.GMarkers.main[indexofPoint];
            AddOverlay(defaultMarker,attributes);
            AddOverlay(hoverMarker,attributes);
            
        }else{

            // add default FIU marker
            var point = new GLatLng(geom.getLatLng().lat(), geom.getLatLng().lng());
            //var defaultMarker = new GMarker(point);
            var Icon = new GIcon(geom.getIcon());
            Icon.image = FIUMAPS.GMarkers.Marker.DEFAULT;

            defaultMarker = new GMarker(point, Icon);

            AddOverlay(defaultMarker,attributes);

            // add Hover FIU marker
            var hoverIcon = new GIcon(geom.getIcon());
            hoverIcon.image = FIUMAPS.GMarkers.Marker.HOVER;         
            hoverMarker = new GMarker(defaultMarker.getPoint(),{clickable:false, icon:hoverIcon});
            AddOverlay(hoverMarker, attributes); // hover
              
             
            FIUMAPS.Points.Tracker.push(attributes.SERVICE_ID);
            FIUMAPS.Points.GMarkers.main.push(defaultMarker);
            FIUMAPS.Points.GMarkers.hover.push(hoverMarker);
                
                
            // add event listener to geometries
            GEvent.addListener(defaultMarker,'click',function(){
                defaultMarker.openInfoWindowHtml(FIUMAPS.HTMLPopUp.getMarkerHTMLWindows(attributes));
            });                          
           
        }   
        hoverMarker.hide(); 
        
        
        // add event listener to links
        GEvent.addDomListener(link,'mouseover',function(){
            if(attributes.CAMPUS_ID != FIUMAPS.CampusInfo.getCurrentCampusID()){
                FIUMAPS.CampusInfo.goToCampusByID(attributes.CAMPUS_ID);
            }
            defaultMarker.openInfoWindowHtml(FIUMAPS.HTMLPopUp.getMarkerHTMLWindows(attributes));
            hoverMarker.show();
        }); 
        GEvent.addDomListener(link,'mouseout',function(){
            MarkeronMouseOutFunc();
            hoverMarker.hide();
        });  
        GEvent.addDomListener(link,'click',function(){
            MarkeronMouseClickFunc(defaultMarker,attributes,false);
        });    
                                                              
    }   
}
function mapzoom(direction){
    if(direction == "in"){
        gmap.zoomIn();
    }else{
        gmap.zoomOut();
    }
}

